from app.controllers.base_controller import BaseController
from app.crud.user_crud import UserCRUD
from app.models.base import IdType
from app.models.user import User
from app.schemas.result_schema import ResultFormat, ResultModel
from app.schemas.user_schema import (
    UserAssignPermission,
    UserUpdate,
    UserCreate,
    UserUpdatePassword,
    UserUpdateAvatar, )


class UserController(BaseController[UserCRUD,User,UserCreate,UserUpdate]):
    async def assign_permissions(self, permission: UserAssignPermission) -> ResultModel[bool]:
        result = await self.crud.assign_permissions(permission=permission)
        return ResultFormat.result_bool(data=result, model_name="分配权限")

    async def update_avatar(self,avatar: UserUpdateAvatar) -> ResultModel[User]:
        result = await self.crud.update_avatar(avatar_in=avatar)
        return ResultFormat.result_model(data=result, model_name="修改用户头像")

    async def update_password(self,password_in: UserUpdatePassword) -> ResultModel[bool]:
        result = await self.crud.update_password(password_in=password_in)
        return ResultFormat.result_bool(data=result, model_name="更新密码")

    async def reset_password(self,id: IdType) -> ResultModel[bool]:
        result = await self.crud.reset_password(id=id)
        return ResultFormat.result_bool(data=result, model_name="重置密码")